import request from '@/plugin/axios'
import util from '@/libs/util.js'

export function getCompanyTable(pageno, pagesize,formdata){

    var data = {};
    data.pageno = pageno;
    data.pagesize = pagesize;
    data.UserId = util.cookies.get('uuid');
    if (formdata) {
        data = Object.assign(formdata, data);
    }
    return request({
        url: '/Company/List',
        method: 'post',
        data
    }).then(res=>{
        if(res.data && res.data.length>0){
            let _data=[];
            let b=(pageno-1)*pagesize;
            let e = (b+pagesize);
            if(e>res.data.length) e = res.data.length;
            for(let i=b;i<e;i++){
                _data.push( res.data[i] );
            }
            res.data = _data;
        }
        return res;
    });
}

/**
 * 保存企业
 * @param {*} code
 * @param {*} name
 * @param {*} address
 * @param {HTMLElement.file} logofile
 */
export function saveCompany(code,name,address,logofile){
    let data={
        CompanyCode:code,
        CompanyName:name,
        CompanyAddress:address,
        CompanyLogo:logofile,
        projectNo:''
    };

    return request({
        url: '/Company/Add',
        method: 'post',
        data:data
    });
}

export function deleteCompany(id){
    return request({
        url: '/Company/Delete',
        method: 'post',
        data:{Id:id}
    });
}
